<template>
    <div class="page_wageDetail">
        <van-nav-bar title="工资详情" left-arrow @click-left="$router.back()" right-text="历史工资条"
            @click-right="clickWageRecords" />

        <job-item-for-wage :id="needObj.id" :keyWord="'wageSettlement'" :jobItem="needObj" :routeName="$route.name">
        </job-item-for-wage>

        <van-divider
            :style="{ color: '#323233', borderColor: '#BCBCBC', padding: '10px 66px 0', margin: '0', backgroundColor: '#FFFFFF', fontWeight: 'bold'}">
            我的工资条（最新）
        </van-divider>

        <van-cell-group>
            <van-cell v-for="(item, key) in wageDetailList" :title="item.categoryname" :value="item.money" :key="key" />
        </van-cell-group>

    </div>
</template>

<script>
import jobItemForWage from './jobItemForWage'
import {formatDate} from '@/utils/format'
import {Toast} from 'vant'

export default {
  name: 'wageDetail',
  components: {
    jobItemForWage
  },
  data() {
    return {
      needObj: '',
      wageDetailList: []
    }
  },
  created() {
    this.getJobInfo()
    this.getSalaryInfoById()
  },

  methods: {
    getJobInfo() {
      this.$api.job
        .getMyJobInfo({
          jobId: this.$route.params.id,
          jobUserId: this.$route.query.jobuserid ? this.$route.query.jobuserid : "",
          salaryInfoId: this.$route.query.salaryinfoid
        })
        .then(res => {
          if (res.code === 200) {
            if (res.data && res.data.jobs.id) {
              this.needObj = {...res.data.jobs, isLendMoney: 1}
              this.needObj.signuptime = formatDate(res.data.jobs.report_time, '-', ':')
              this.needObj.apply_time = formatDate(res.data.jobs.report_time, '-', ':')
              this.needObj.salarytime = formatDate(res.data.jobs.salaryuptime, '-', ':')
              this.needObj.start_work_time = res.data.jobs.startdate
              this.needObj.end_work_time = res.data.jobs.work_end_time
            } else {
              Toast('当前工作信息已失效！')
            }
          } else {
            Toast('请求失败请重试！')
          }
        })
    },

    getSalaryInfoById() {
      let params = {
        SalaryInfoId: this.$route.query.salaryinfoid
      }
      this.$api.myCompany.getSalaryInfoById(params).then(res => {
        if (res.code === 200) {
          this.wageDetailList = res.data
        } else {
          Toast('请求失败请重试！')
        }
      })
    },

    clickWageRecords() {
      this.$router.push({
        path: `/salaryList`,
        query: {
          jobid: this.$route.params.id
        }
      })
    }
  },

  mounted() {}
}
</script>

<style scoped>
</style>
